home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / cswsk110 / tinyftp.frm < prev    next >
Text File  |  1995-12-07  |  13KB  |  445 lines

  1. VERSION 2.00
  2. Begin Form Client 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "FTP Client"
  6.    ClientHeight    =   4185
  7.    ClientLeft      =   1245
  8.    ClientTop       =   1905
  9.    ClientWidth     =   7095
  10.    FontBold        =   0   'False
  11.    FontItalic      =   0   'False
  12.    FontName        =   "MS Sans Serif"
  13.    FontSize        =   8.25
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   4875
  17.    Left            =   1185
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   4185
  20.    ScaleWidth      =   7095
  21.    Top             =   1275
  22.    Width           =   7215
  23.    Begin Socket Socket2 
  24.       Backlog         =   1
  25.       Binary          =   -1  'True
  26.       Blocking        =   -1  'True
  27.       Broadcast       =   0   'False
  28.       BufferSize      =   0
  29.       HostAddress     =   ""
  30.       HostFile        =   ""
  31.       HostName        =   ""
  32.       InLine          =   0   'False
  33.       Interval        =   0
  34.       KeepAlive       =   0   'False
  35.       Left            =   720
  36.       Linger          =   0
  37.       LocalPort       =   0
  38.       LocalService    =   ""
  39.       Peek            =   0   'False
  40.       Protocol        =   0
  41.       RecvLen         =   0
  42.       RemotePort      =   0
  43.       RemoteService   =   ""
  44.       ReuseAddress    =   0   'False
  45.       Route           =   -1  'True
  46.       SendLen         =   0
  47.       TabIndex        =   24
  48.       Timeout         =   0
  49.       Top             =   3600
  50.       Type            =   1
  51.       Urgent          =   0   'False
  52.    End
  53.    Begin Socket Socket1 
  54.       Backlog         =   1
  55.       Binary          =   -1  'True
  56.       Blocking        =   -1  'True
  57.       Broadcast       =   0   'False
  58.       BufferSize      =   0
  59.       HostAddress     =   ""
  60.       HostFile        =   ""
  61.       HostName        =   ""
  62.       InLine          =   0   'False
  63.       Interval        =   0
  64.       KeepAlive       =   0   'False
  65.       Left            =   120
  66.       Linger          =   0
  67.       LocalPort       =   0
  68.       LocalService    =   ""
  69.       Peek            =   0   'False
  70.       Protocol        =   0
  71.       RecvLen         =   0
  72.       RemotePort      =   0
  73.       RemoteService   =   ""
  74.       ReuseAddress    =   0   'False
  75.       Route           =   -1  'True
  76.       SendLen         =   0
  77.       TabIndex        =   23
  78.       Timeout         =   0
  79.       Top             =   3600
  80.       Type            =   1
  81.       Urgent          =   0   'False
  82.    End
  83.    Begin CommandButton CopyButton 
  84.       Caption         =   "Copy"
  85.       Enabled         =   0   'False
  86.       Height          =   375
  87.       Left            =   3840
  88.       TabIndex        =   22
  89.       Top             =   3600
  90.       Width           =   1215
  91.    End
  92.    Begin Frame TransferFrame 
  93.       BackColor       =   &H00C0C0C0&
  94.       Caption         =   "Transfer"
  95.       Height          =   1695
  96.       Left            =   4440
  97.       TabIndex        =   21
  98.       Top             =   1680
  99.       Width           =   2535
  100.       Begin CheckBox BinaryTransfer 
  101.          BackColor       =   &H00C0C0C0&
  102.          Caption         =   "Binary"
  103.          Height          =   255
  104.          Left            =   240
  105.          TabIndex        =   15
  106.          Top             =   1200
  107.          Width           =   855
  108.       End
  109.       Begin OptionButton RemoteTransfer 
  110.          BackColor       =   &H00C0C0C0&
  111.          Caption         =   "To Remote System"
  112.          Height          =   255
  113.          Left            =   240
  114.          TabIndex        =   14
  115.          Top             =   840
  116.          Width           =   2055
  117.       End
  118.       Begin OptionButton LocalTransfer 
  119.          BackColor       =   &H00C0C0C0&
  120.          Caption         =   "To Local System"
  121.          Height          =   375
  122.          Left            =   240
  123.          TabIndex        =   13
  124.          Top             =   430
  125.          Value           =   -1  'True
  126.          Width           =   1935
  127.       End
  128.    End
  129.    Begin Frame FileFrame 
  130.       BackColor       =   &H00C0C0C0&
  131.       Caption         =   "File"
  132.       Height          =   1695
  133.       Left            =   120
  134.       TabIndex        =   20
  135.       Top             =   1680
  136.       Width           =   4215
  137.       Begin TextBox RemoteFile 
  138.          BackColor       =   &H00C0C0C0&
  139.          Height          =   300
  140.          Left            =   1200
  141.          TabIndex        =   12
  142.          Top             =   1080
  143.          Width           =   2775
  144.       End
  145.       Begin TextBox LocalFile 
  146.          BackColor       =   &H00C0C0C0&
  147.          Height          =   300
  148.          Left            =   1200
  149.          TabIndex        =   10
  150.          Top             =   720
  151.          Width           =   2775
  152.       End
  153.       Begin Label RemotePath 
  154.          BackStyle       =   0  'Transparent
  155.          Height          =   300
  156.          Left            =   1200
  157.          TabIndex        =   8
  158.          Top             =   360
  159.          Width           =   2775
  160.       End
  161.       Begin Label Label7 
  162.          BackStyle       =   0  'Transparent
  163.          Caption         =   "Directory:"
  164.          Height          =   255
  165.          Left            =   120
  166.          TabIndex        =   7
  167.          Top             =   360
  168.          Width           =   855
  169.       End
  170.       Begin Label Label6 
  171.          BackStyle       =   0  'Transparent
  172.          Caption         =   "&Remote:"
  173.          Height          =   255
  174.          Left            =   120
  175.          TabIndex        =   11
  176.          Top             =   1080
  177.          Width           =   735
  178.       End
  179.       Begin Label Label5 
  180.          BackStyle       =   0  'Transparent
  181.          Caption         =   "&Local:"
  182.          Height          =   255
  183.          Left            =   120
  184.          TabIndex        =   9
  185.          Top             =   720
  186.          Width           =   615
  187.       End
  188.    End
  189.    Begin CommandButton ActionButton 
  190.       Caption         =   "Connect"
  191.       Height          =   375
  192.       Left            =   2160
  193.       TabIndex        =   17
  194.       Top             =   3600
  195.       Width           =   1215
  196.    End
  197.    Begin Frame UserFrame 
  198.       BackColor       =   &H00C0C0C0&
  199.       Caption         =   "User"
  200.       Height          =   1455
  201.       Left            =   3600
  202.       TabIndex        =   19
  203.       Top             =   120
  204.       Width           =   3375
  205.       Begin TextBox Password 
  206.          BackColor       =   &H00C0C0C0&
  207.          Height          =   300
  208.          Left            =   1080
  209.          PasswordChar    =   "*"
  210.          TabIndex        =   6
  211.          Top             =   840
  212.          Width           =   1935
  213.       End
  214.       Begin TextBox UserName 
  215.          BackColor       =   &H00C0C0C0&
  216.          Height          =   300
  217.          Left            =   1080
  218.          TabIndex        =   4
  219.          Top             =   480
  220.          Width           =   1935
  221.       End
  222.       Begin Label Label4 
  223.          BackColor       =   &H00FFFFFF&
  224.          BackStyle       =   0  'Transparent
  225.          Caption         =   "&Password:"
  226.          Height          =   255
  227.          Left            =   120
  228.          TabIndex        =   5
  229.          Top             =   840
  230.          Width           =   975
  231.       End
  232.       Begin Label Label3 
  233.          BackStyle       =   0  'Transparent
  234.          Caption         =   "&Username:"
  235.          Height          =   255
  236.          Left            =   120
  237.          TabIndex        =   3
  238.          Top             =   480
  239.          Width           =   975
  240.       End
  241.    End
  242.    Begin Frame RemoteFrame 
  243.       BackColor       =   &H00C0C0C0&
  244.       Caption         =   "System"
  245.       Height          =   1455
  246.       Left            =   120
  247.       TabIndex        =   18
  248.       Top             =   120
  249.       Width           =   3375
  250.       Begin ComboBox Hostname 
  251.          BackColor       =   &H00C0C0C0&
  252.          Height          =   300
  253.          Left            =   1200
  254.          Sorted          =   -1  'True
  255.          TabIndex        =   0
  256.          Top             =   480
  257.          Width           =   1935
  258.       End
  259.       Begin TextBox IPAddress 
  260.          BackColor       =   &H00C0C0C0&
  261.          Height          =   300
  262.          Left            =   1200
  263.          TabIndex        =   2
  264.          Top             =   840
  265.          Width           =   1575
  266.       End
  267.       Begin Label Label2 
  268.          BackStyle       =   0  'Transparent
  269.          Caption         =   "IP &Address:"
  270.          Height          =   255
  271.          Left            =   120
  272.          TabIndex        =   1
  273.          Top             =   840
  274.          Width           =   1095
  275.       End
  276.       Begin Label Label1 
  277.          BackStyle       =   0  'Transparent
  278.          Caption         =   "&Hostname:"
  279.          Height          =   255
  280.          Left            =   120
  281.          TabIndex        =   16
  282.          Top             =   480
  283.          Width           =   975
  284.       End
  285.    End
  286.    Begin Menu FileMenu 
  287.       Caption         =   "&File"
  288.       Begin Menu ExitApp 
  289.          Caption         =   "E&xit"
  290.       End
  291.    End
  292. End
  293.  
  294. Option Explicit
  295.  
  296. Sub ActionButton_Click ()
  297.     Dim Address As String
  298.  
  299.     If Not Socket1.Connected Then
  300.         ActionButton.Enabled = False
  301.         ActionButton.Default = False
  302.         Client.MousePointer = 11
  303.         Address = Trim$(Hostname.Text)
  304.         If Len(Address) = 0 Then Address = Trim$(IPAddress.Text)
  305.         If Not FTPConnect(Address) Then
  306.             ActionButton.Enabled = True
  307.             ActionButton.Default = True
  308.             Client.MousePointer = 0
  309.             MsgBox "Unable to connect to remote host"
  310.             Exit Sub
  311.         End If
  312.         If Not FTPLogin(Trim$(UserName.Text), Trim$(Password.Text)) Then
  313.             Client.MousePointer = 0
  314.             Socket1.Action = SOCKET_CLOSE
  315.             ActionButton.Enabled = True
  316.             ActionButton.Default = True
  317.             Exit Sub
  318.         End If
  319.         Client.MousePointer = 0
  320.         FTPGetDirectory
  321.         ActionButton.Caption = "Disconnect"
  322.         ActionButton.Enabled = True
  323.         CopyButton.Enabled = True
  324.     Else
  325.         Socket1.Action = SOCKET_CLOSE
  326.         ActionButton.Caption = "Connect"
  327.         ActionButton.Default = True
  328.         CopyButton.Enabled = False
  329.         Hostname.SetFocus
  330.     End If
  331. End Sub
  332.  
  333. Sub CopyButton_Click ()
  334.     Dim SrcFile As String, DstFile As String
  335.     
  336.     CopyButton.Enabled = False
  337.     Client.MousePointer = 11
  338.  
  339.     If LocalTransfer.Value Then
  340.         SrcFile = Trim$(RemoteFile.Text)
  341.         DstFile = Trim$(LocalFile.Text)
  342.         If Not FTPGetFile(SrcFile, DstFile) Then
  343.             Client.MousePointer = 0
  344.             MsgBox "Could not copy remote file"
  345.         End If
  346.     Else
  347.         SrcFile = Trim$(LocalFile.Text)
  348.         DstFile = Trim$(RemoteFile.Text)
  349.         If Not FTPPutFile(SrcFile, DstFile) Then
  350.             Client.MousePointer = 0
  351.             MsgBox "Could not copy local file"
  352.         End If
  353.     End If
  354.     
  355.     CopyButton.Enabled = True
  356.     Client.MousePointer = 0
  357. End Sub
  358.  
  359. Sub ExitApp_Click ()
  360.     Unload Client
  361. End Sub
  362.  
  363. Sub Form_Load ()
  364.     Dim Host As String
  365.  
  366.     '
  367.     ' Initialize hostname combo box
  368.     '
  369.     On Error Resume Next
  370.     Socket1.HostFile = "HOSTS"
  371.     If Err = 0 Then
  372.         Host$ = Socket1.GetFirstHost
  373.         While Host$ <> ""
  374.             Hostname.AddItem Host$
  375.             Host$ = Socket1.GetNextHost
  376.         Wend
  377.     End If
  378.     Socket1.HostFile = ""
  379.  
  380.     '
  381.     ' Initialize the other controls
  382.     '
  383.     ActionButton.Caption = "Connect"
  384.     ActionButton.Default = True
  385.     ActionButton.Enabled = False
  386. End Sub
  387.  
  388. Sub Form_Unload (Cancel As Integer)
  389.     If Socket1.Connected Then Socket1.Action = SOCKET_CLOSE
  390.     If Socket2.Listening Or Socket2.Connected Then Socket2.Action = SOCKET_CLOSE
  391.     End
  392. End Sub
  393.  
  394. Sub Hostname_Change ()
  395.     If (Len(Hostname.Text) > 0 Or Len(IPAddress.Text) > 0) And Len(UserName.Text) > 0 Then
  396.         ActionButton.Enabled = True
  397.     Else
  398.         ActionButton.Enabled = False
  399.     End If
  400. End Sub
  401.  
  402. Sub Hostname_GotFocus ()
  403.     Hostname.SelStart = 0
  404.     Hostname.SelLength = Len(Hostname.Text)
  405. End Sub
  406.  
  407. Sub Hostname_KeyPress (KeyAscii As Integer)
  408.     IPAddress.Text = ""
  409. End Sub
  410.  
  411. Sub IPAddress_Change ()
  412.     If Len(Hostname.Text) > 0 Or Len(IPAddress.Text) > 0 Then
  413.         ActionButton.Enabled = True
  414.     Else
  415.         ActionButton.Enabled = False
  416.     End If
  417. End Sub
  418.  
  419. Sub IPAddress_GotFocus ()
  420.     IPAddress.SelStart = 0
  421.     IPAddress.SelLength = Len(IPAddress.Text)
  422. End Sub
  423.  
  424. Sub IPAddress_KeyPress (KeyAscii As Integer)
  425.     Hostname.Text = ""
  426. End Sub
  427.  
  428. Sub Socket1_Close ()
  429.     Socket1.Action = SOCKET_CLOSE
  430.     ActionButton.Caption = "Connect"
  431.     ActionButton.Default = True
  432.     CopyButton.Enabled = False
  433.     MsgBox "Remote server closed control connection"
  434. End Sub
  435.  
  436. Sub UserName_Change ()
  437.     If Len(UserName.Text) > 0 And (Len(Hostname.Text) > 0 Or Len(IPAddress.Text) > 0) Then
  438.         ActionButton.Enabled = True
  439.     Else
  440.         ActionButton.Enabled = False
  441.     End If
  442.  
  443. End Sub
  444.  
  445.